package com.key.controller.user;

import com.key.common.R;
import com.key.entity.SysUser;
import com.key.service.IndexService;
import io.swagger.annotations.*;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.spring.web.json.Json;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: li
 * @CreateTime: 2023-02-17  10:54
 */

@Controller
@RequestMapping("/index")
@Api(value = "用户首页",tags = "用户首页数据接口")
//用户端首页的相关功能
public class IndexController {

    @Autowired
    private IndexService indexService;




    //SecurityUtils.getSubject().getPrincipal();
//    Subject subject = SecurityUtils.getSubject();
//    String s = String.valueOf(subject.getPrincipal());
//

//    Subject subject = SecurityUtils.getSubject();
//    String s = String.valueOf(subject.getPrincipal());



//    @RequestMapping(value = "/showAllUserApplyAssets",method = RequestMethod.GET)
//    @ApiOperation(value = "用户资产接口",notes = "查询当前用户所有资产信息",httpMethod = "get",response = Json.class)
//    public R showAllUserApplyAssets(){
//        R r = new R();
//
//        return r;
//    }



    /**
     * 查询当前用户所有资产及其状态
     * @return
     */
    @RequestMapping(value = "/showAllUserAssets",method = RequestMethod.GET)
    @ApiOperation(value = "用户资产接口",notes = "查询当前用户所有资产及其状态",httpMethod = "get",response = Json.class)
   // @ApiImplicitParam(name = "userName",value = "用户名",required = true,dataType = "String",paramType ="query")
    @ResponseBody
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })


    public R showAllUserAssets(){
        Subject subject = SecurityUtils.getSubject();
        String s = String.valueOf(subject.getPrincipal());
        SysUser sysUser = indexService.showUserInfoByUserName(s);
        Integer assetsManagerId=1;//sysUser.getUserId();


        List<Map<String, Object>> mapList = indexService.showUserAssetsState(assetsManagerId);

        System.out.println((mapList));
        R r = new R();
        r.setData(mapList);
        r.setCode(200);
        r.setMsg("success");
        return r;
    }

    //查询当前用户的所有盘点状态及状态

    /**
     * 查询当前用户的所有盘点状态及状态
     * @return
     */
    @RequestMapping(value = "/showAllUserInventory",method = RequestMethod.GET)
    @ApiOperation(value = "用户盘点任务接口",notes = "查询当前用户所有盘点任务及状态",httpMethod = "get",response = Json.class)
    //@ApiImplicitParam(name = "userName",value = "用户名",required = true,dataType = "String",paramType ="query")
    @ResponseBody
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R showAllUserInventory(){
        Subject subject = SecurityUtils.getSubject();
        String s = String.valueOf(subject.getPrincipal());
        SysUser sysUser = indexService.showUserInfoByUserName(s);
        Integer assetsManagerId=1;//sysUser.getUserId();
        List<Map<String, Object>> mapList = indexService.showUserInventoryState(assetsManagerId);

        System.out.println((mapList));
        R r = new R();
        r.setData(mapList);
        r.setCode(200);
        r.setMsg("success");
        return r;
    }

    //查询当前用户的所有待签收资产

    /**
     * 查询当前用户的所有待签收资产
     * @return
     */
    @RequestMapping(value = "/showAllUserSignAssets",method = RequestMethod.GET)
    @ApiOperation(value = "用户待签收资产接口",notes = "查询当前用户所有待签收资产数量",httpMethod = "get",response = Json.class)
    //@ApiImplicitParam(name = "userName",value = "用户名",required = true,dataType = "String",paramType ="query")
    @ResponseBody
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R showAllUserSignAssets(){
        Subject subject = SecurityUtils.getSubject();
        String s = String.valueOf(subject.getPrincipal());

        SysUser sysUser = indexService.showUserInfoByUserName(s);
        Integer assetsManagerId=1;//sysUser.getUserId();
        R r = indexService.showUserSignAssetsState(assetsManagerId);
        return r;
    }

    




}
